package com.salim.leetcode.$46;

import lombok.extern.slf4j.Slf4j;

import java.util.*;

@Slf4j
public class Permutations {
    List<List<Integer>> result = new ArrayList<>();
    public List<List<Integer>> permute(int[] nums) {
        List<Integer> remain = new ArrayList<Integer>();
        for(int i=0;i<nums.length;i++){
            remain.add(nums[i]);
        }
        for(int i=0;i<nums.length;i++){
            List<Integer> subResult = new ArrayList<>();
            List<Integer> remainList = new ArrayList<>(remain);
            remainList.remove(i);
            subResult.add(nums[i]);
            loop(remainList,subResult);
        }
        return result;
    }

    public void loop(List<Integer> nums,List<Integer> lastList){
        if(nums.size()==0){
            result.add(lastList);
            return;
        }
        for(int i=0;i<nums.size();i++){
            List<Integer> subResult = new ArrayList<>(lastList);
            List<Integer> remainList = new ArrayList<>(nums);
            remainList.remove(i);
            subResult.add(nums.get(i));
            loop(remainList,subResult);
        }
    }

    public static void main(String[] args) {
        Permutations w = new Permutations();
        log.info("Permutations输出结果1：{}", w.permute(new int[]{1,2,3}));
    }
}
